package com.jack.lib.app

import android.app.Application
import android.content.Context
import android.content.res.Resources
import android.util.Log
import com.blankj.utilcode.util.CrashUtils
import com.blankj.utilcode.util.ProcessUtils
import com.jack.lib.Constant
import com.jack.lib.base.BaseApplication
import com.jack.lib.base.IAttributesInterceptor
import com.jack.lib.base.header.HeaderStyleTheme
import com.jack.lib.base.header.JHeaderManager
import com.jack.lib.base.header.style.LightNormalStyle
import com.jack.lib.core.ext.MM
import com.jack.lib.core.ext.fake
import com.jack.lib.core.ui.JAuto
import com.jack.lib.core.utils.JLog
import com.jeremy.retrofitmock.RetrofitMock
import me.jessyan.autosize.AutoSizeConfig
import me.jessyan.autosize.unit.Subunits

/**
 * author : chong.huang
 * create : 2021/12/30
 * desc   :
 */
class App : Application() {

    private var attributesInterceptor: IAttributesInterceptor = object : IAttributesInterceptor { }

    override fun onCreate() {
        super.onCreate()

        ProcessUtils.isMainProcess().fake { return }
        CrashUtils.init {
            JLog.e("jlog", Log.getStackTraceString(it.throwable))
        }

        AutoSizeConfig.getInstance()
            .unitsManager
            .setSupportDP(false)
            .setSupportSP(false)
            .setDesignSize(750f, 1334f)
            .supportSubunits = Subunits.MM

        RetrofitMock.init(this, "mock_demo.json")

        JHeaderManager.defaultTheme(HeaderStyleTheme.LIGHT_NORMAL)
        JHeaderManager.configStyle(HeaderStyleTheme.LIGHT_NORMAL) { object : LightNormalStyle() {
            override var elevation: Int = 10.MM
        } }

        BaseApplication.bindLifecycleAndAuto(this)

        Constant.host = Constant.host
    }

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(attributesInterceptor.attachBaseContext(base))
    }
    override fun getResources(): Resources {
        return JAuto.autoXDpi(750f, super.getResources())
    }
}